import axios from '@/libs/api.request'
import { getToken } from '@/libs/util'

export function addTraining (data) {
    return axios.request({
        url: '/practicalTraining/add',
        method: 'post',
        data
    })
}

export function updateTraining (data) {
    return axios.request({
        url: '/practicalTraining/update',
        method: 'post',
        data
    })
}

export function queryTrainingList (data) {
    return axios.request({
        url: '/practicalTraining/list',
        method: 'post',
        data
    })
}

export function queryTrainingScoreList (data) {
    return axios.request({
        url: '/practicalTrainingStu/list',
        method: 'post',
        data
    })
}

export function publishTraining (id) {
    return axios.request({
        url: '/practicalTraining/publish',
        method: 'get',
        params: {
            id
        }
    })
}

export function deleteTraining (id) {
    return axios.request({
        url: '/practicalTraining/delete',
        method: 'get',
        params: {
            id
        }
    })
}

export function queryTrainingInfo (id) {
    return axios.request({
        url: '/practicalTraining/queryById',
        method: 'post',
        params: {
            id
        }
    })
}

export function downloadTrainingStuReport (params) {
    const query = Object.keys(params).map(k => {
        return `${k}=${params[k]}`
    }).join('&')
    window.open(`/dev/practicalTrainingStu/downloadReportZip?Authorization=${getToken()}&${query}`)
}

export function distributionDiagram (data) {
    return axios.request({
        url: '/practicalTrainingStu/distributionDiagram',
        method: 'post',
        data: data
    })
}
